const getIp = require('./gei-ip')
const log = require("./log-util");
const subIpChange = require('./dnspod-support');

let tempIp = '127.0.0.1'
function runTask(task) {
    getIp(task).then(ip => task(ip))
    setInterval(() => getIp(task).then(ip => task(ip)), 30000)
}


function bashTask(ip){
    if (ip !== tempIp && ip !== '127.0.0.1') {
        log.info('task.js', `now ip is ${ip}, try to update ip`)
        subIpChange(ip).then(tempIp = ip)
    }
}


runTask(bashTask)
